﻿using System;
using System.Windows.Forms;
using WeightConverterNamespace;
using Presentation;
using Infrastructure;

namespace WeightConverterGUI
{
    public partial class MainForm : Form, IView
    {
        TextBox [] listTBox;
        int numOfTBoxs;
        TxtLogger txtLogger;
        HTMLLogger htmlLogger;

        public MainForm()
        {
            InitializeComponent();
            numOfTBoxs = 5;
            listTBox = new TextBox[numOfTBoxs];
            listTBox[0] = tBoxKg;
            listTBox[1] = tBoxPound;
            listTBox[2] = tBoxOunce;
            listTBox[3] = tBoxDram;
            listTBox[4] = tBoxGrain;
            txtLogger = new TxtLogger();
            htmlLogger = new HTMLLogger();
            new Presenter(this, txtLogger);          
        }
        public int FromType
        {
            get { return comboBoxFromType.SelectedIndex; }
        }
        public string FromValue
        {
            get { return listTBox[comboBoxFromType.SelectedIndex].Text; }
        }
        public string FromKg
        {
            get { return tBoxKg.Text; }
        }
        public string FromPound
        {
            get { return tBoxPound.Text; }
        }
        public string FromOunce
        {
            get { return tBoxOunce.Text; }
        }
        public string FromDram
        {
            get { return tBoxDram.Text; }
        }
        public string FromGrain
        {
            get { return tBoxGrain.Text; }
        } 
        public string ToKg
        {
            set { tBoxKg.Text = value; }
        }
        public string ToPound
        {
            set { tBoxPound.Text = value; }
        }
        public string ToOunce
        {
            set { tBoxOunce.Text = value; }
        }
        public string ToDram
        {
            set { tBoxDram.Text = value; }
        }
        public string ToGrain
        {
            set { tBoxGrain.Text = value; }
        }
        public string ErrorMessage
        {
            set { if(value != "") MessageBox.Show(value); }
        }
        public bool TBoxKgReadOnly
        {
            set { tBoxKg.ReadOnly = value; }
        }
        public bool TBoxPoundReadOnly
        {
            set { tBoxPound.ReadOnly = value; }
        }
        public bool TBoxOunceReadOnly
        {
            set { tBoxOunce.ReadOnly = value; }
        }
        public bool TBoxDramReadOnly
        {
            set { tBoxDram.ReadOnly = value; }
        }
        public bool TBoxGrainReadOnly
        {
            set { tBoxGrain.ReadOnly = value; }
        }
        public bool HTMLLoggerMenuItemChecked
        {
            get { return HTMLLoggerMenuItem.Checked; }
            set { HTMLLoggerMenuItem.Checked = value; } 
        }
        public bool TxtLoggerMenuItemChecked
        {
            get { return txtLoggerMenuItem.Checked; }
            set { txtLoggerMenuItem.Checked = value; }
        }

        public event Action OnCalculateClick;
        public event Action SelectedIndexChanged;
        public event Action OnReadLogButtonClick;
        public event Action OnDeleteLogButtonClick;
        public event Action OnHTMLLoggerMenuItemClick;
        public event Action OnTxtLoggerMenuItemClick;
        public event DLogHandler LogHandler;
                
        private void calculateButton_Click(object sender, EventArgs e)
        {
            OnCalculateClick();
        }
        private void comboBoxFromType_SelectedIndexChanged(object sender, EventArgs e)
        {            
            SelectedIndexChanged();            
        }
        private void readLogButton_Click(object sender, EventArgs e)
        {
            OnReadLogButtonClick();
        }
        private void readLogToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OnReadLogButtonClick();
        }
        private void deleteLogToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OnDeleteLogButtonClick();
        }
        private void txtLoggerMenuItem_Click(object sender, EventArgs e)
        {
            OnTxtLoggerMenuItemClick();
            LogHandler(txtLogger);
        }
        private void HTMLLoggerMenuItem_Click(object sender, EventArgs e)
        {
            OnHTMLLoggerMenuItemClick();
            LogHandler(htmlLogger);
        }
    }
}
